/**
 * @file ShowInfoDialogFragment.java
 * @create 下午4:09:11
 * @author CX
 * @description 一个显示内容的对话框
 */
package cn.edu.hstc.wm.ui.fragment;

import android.annotation.SuppressLint;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.TypedValue;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import cn.edu.hstc.wm.R;

//测试用类
public class ShowInfoDialogFragment extends DialogFragment {

	public static ShowInfoDialogFragment newInstance() {
		ShowInfoDialogFragment dialogFragment = new ShowInfoDialogFragment();
		return dialogFragment;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		if (getDialog() != null) {
			getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); // 设置对话框无标题
			getDialog().getWindow().setBackgroundDrawableResource(
					android.R.color.transparent); // 设置背景透明
		}

		View root = inflater.inflate(R.layout.show_info_dialog_layout,
				container, false);
		return root;
	}

	@SuppressLint("NewApi")
	@SuppressWarnings("deprecation")
	@Override
	public void onStart() {
		super.onStart();
		// change dialog width
		if (getDialog() != null) {

			int fullWidth = getDialog().getWindow().getAttributes().width;

			// 版本选择
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
				Display display = getActivity().getWindowManager()
						.getDefaultDisplay();
				Point size = new Point();
				display.getSize(size);
				fullWidth = size.x;
			} else {
				Display display = getActivity().getWindowManager()
						.getDefaultDisplay();
				fullWidth = display.getWidth();
			}

			final int padding = (int) TypedValue.applyDimension(
					TypedValue.COMPLEX_UNIT_DIP, 24, getResources()
							.getDisplayMetrics());

			int w = fullWidth - padding;
			int h = getDialog().getWindow().getAttributes().height;

			getDialog().getWindow().setLayout(w, h); // 设置位置
		}
	}
}
